package com.tanhua.server.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

/**
 * @Author YuShiLong
 * @Date 2021/4/14 20:15
 * @Version 1.0
 */

/**
 * 负责与dubbo服务进行交互
 */
@Service
public class RecommendUserService {

    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    public TodayBest queryTodayBest(Long userId) {
        RecommendUser recommendUser = recommendUserApi.queryWithMaxScore(userId);
        if (recommendUser != null) {
            TodayBest todayBest = new TodayBest();
            //为推荐用户设置值
            todayBest.setFateValue(new Double(Math.floor(recommendUser.getScore())).longValue());
            todayBest.setId(recommendUser.getUserId());
            return todayBest;
        }
        return null;
    }

    public PageInfo<RecommendUser> queryRecommendUserList(Long userId, Integer page, Integer pageSize) {
        return recommendUserApi.queryPageInfo(userId, page, pageSize);
    }

    /**
     * 查询推荐好友的缘分值
     *
     * @param userId
     * @param toUserId
     * @return
     */
    double queryScore(Long userId, Long toUserId) {
        return this.recommendUserApi.queryScore(userId, toUserId);
    }
}
